package com.woniu.uums.controller;

import com.woniu.common.utils.PageParam;
import com.woniu.common.utils.ResponseData;
import com.woniu.uums.dto.*;
import com.woniu.uums.pojo.ZyManage;
import com.woniu.uums.service.AuthorityService;
import com.woniu.uums.service.MenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * packageName com.woniu.uums.controller
 *
 * @author zxyang3636
 * @version JDK 8
 * @className AuthorityController
 * @date 2024/8/12
 * @description TODO
 */
@RestController
public class AuthorityController {

    @Autowired
    private AuthorityService authorityService;

    @GetMapping("/selRole")
    public ResponseData<?> selRole() {
        return authorityService.selRole();
    }

    @GetMapping("/selAllMenu")
    public ResponseData<?> selAllMenu() {
        return authorityService.selAllMenu();
    }

    @GetMapping("/selDefaultSelected")
    public ResponseData<?> selDefaultSelected(@RequestParam("roleId") String roleId) {
        return authorityService.selDefaultSelected(roleId);
    }

    @PostMapping("/updateRoleMenu")
    public ResponseData<?> updateRoleMenu(@RequestBody MenuRoleUpdateDTO menuRoleUpdateDTO) {
        return authorityService.updateRoleMenu(menuRoleUpdateDTO);
    }

    /**
     * @param : []
     * @return com.woniu.common.utils.ResponseData<?>
     * @author zxyang3636
     * @date 2024/8/12
     * {@link ResponseData<?>}
     * @description 查询所有接口权限
     */
    @GetMapping("/selRepPath")
    public ResponseData<?> selRepPath() {
        return authorityService.selRepPath();
    }

    /**
     * @param roleId: [roleId]
     * @return com.woniu.common.utils.ResponseData<?>
     * @author zxyang3636
     * @date 2024/8/12
     * {@link ResponseData<?>}
     * @description 查询 某个角色的接口权限
     */
    @GetMapping("/selectReqPathByRoleId")
    public ResponseData<?> selectReqPathByRoleId(@RequestParam("roleId") String roleId) {
        return authorityService.selectReqPathByRoleId(roleId);
    }

    @PostMapping("/updateRoleReqPath")
    public ResponseData<?> updateRoleReqPath(@RequestBody ReqPathUpdateDTO reqPathUpdateDTO) {
        return authorityService.updateRoleReqPath(reqPathUpdateDTO);
    }

    /**
     * @param : []
     * @return com.woniu.common.utils.ResponseData<?>
     * @author zxyang3636
     * @date 2024/8/13
     * {@link ResponseData<?>}
     * @description 角色缓存预热
     */
    @ApiOperation(value = "用户-角色缓存预热", notes = "登录用户-角色缓存预热", response = ResponseData.class)
    @GetMapping("/userCachePreheating")
    public ResponseData<?> userCachePreheating() {
        return authorityService.userCachePreheating();
    }

    /**
     * @param : []
     * @return com.woniu.common.utils.ResponseData<?>
     * @author zxyang3636
     * @date 2024/8/13
     * {@link ResponseData<?>}
     * @description 路径缓存预热
     */
    @ApiOperation(value = "路径缓存预热", notes = "请求路径信息缓存预热", response = ResponseData.class)
    @GetMapping("/requestPathCachePreheating")
    public ResponseData<?> requestPathCachePreheating() {
        return authorityService.requestPathCachePreheating();
    }


    @PostMapping("/selUserByCondition")
    public ResponseData<?> selUserByCondition(@RequestBody PageParam<UserQueryDTO> pageParam) {
        return authorityService.selUserByCondition(pageParam);
    }

    @PostMapping("/addUser")
    public ResponseData<?> addUser(@RequestBody ManageAddDTO manageAddDTO) {
        try {
            return authorityService.addUser(manageAddDTO);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @PostMapping("/updateManagePwd")
    public ResponseData<?> updateManagePwd(@RequestBody ZyManage zyManage) {
        return authorityService.updateManagePwd(zyManage);
    }


    @PostMapping("/updateUserRole")
    public ResponseData<?> updateUserRole(@RequestBody ManageUpdateRoleDTO manageUpdateRoleDTO) {
        System.out.println(manageUpdateRoleDTO);
        return null;
    }

    @DeleteMapping("/deleteUser")
    public ResponseData<?> deleteUser(String manageId) {
        return authorityService.deleteUser(manageId);
    }


    @GetMapping("/selManageRoleByMangeId")
    public ResponseData<?> selManageRoleByMangeId(String manageId) {
        return authorityService.selManageRoleByMangeId(manageId);
    }


    @PostMapping("/addManageRole")
    public ResponseData<?> addManageRole(@RequestBody ManageUpdateRoleDTO manageUpdateRoleDTO){
        try {
            return authorityService.addManageRole(manageUpdateRoleDTO);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    @PostMapping("/deleteManageRole")
    public ResponseData<?> deleteManageRole(@RequestBody ManageUpdateRoleDTO manageUpdateRoleDTO){
        return authorityService.deleteManageRole(manageUpdateRoleDTO);
    }
    /**
     * ┌───┐   ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
     * │Esc│   │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│  ┌┐    ┌┐    ┌┐
     * └───┘   └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘  └┘    └┘    └┘
     * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
     * │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │NUM│ / │ * │ - │
     * ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
     * │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │   │
     * ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │
     * │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter  │               │ 4 │ 5 │ 6 │   │
     * ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐     ├───┼───┼───┼───┤
     * │ Shift  │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│  Shift   │     │ ↑ │     │ 1 │ 2 │ 3 │   │
     * ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││
     * │ Ctrl│    │Alt │         Space         │ Alt│    │    │Ctrl│ │ ← │ ↓ │ → │ │   0   │ . │←─┘│
     * └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
     */


}
